/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbravo.pos.admin;

import com.openbravo.basic.BasicException;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.format.Formats;
import java.awt.Component;
import java.util.UUID;


public class JRolesTree extends javax.swing.JPanel {

    private Object m_oId;
    
    public JRolesTree(DirtyManager dirty) {
        initComponents();
      
        m_jName.getDocument().addDocumentListener(dirty);
        
        writeValueEOF();
        
        
    }

    public void writeValueEOF() {
        m_oId = null;
        m_jName.setText(null);
        m_jName.setEnabled(false);
    } 
    
    public void writeValueInsert() {
        m_oId = null;
        m_jName.setText(null);
        m_jName.setEnabled(true);
    }
    
        public void writeValueDelete(Object value) {

        Object[] role = (Object[]) value;
        m_oId = role[0];
        m_jName.setText(Formats.STRING.formatValue(role[1]));
        m_jName.setEnabled(false);
    }   
    

    public void writeValueEdit(Object value) {

        Object[] role = (Object[]) value;
        m_oId = role[0];
        m_jName.setText(Formats.STRING.formatValue(role[1]));
        m_jName.setEnabled(true);
    }    
    

    public Object createValue() throws BasicException {

        Object[] role = new Object[3];
        role[0] = m_oId == null ? UUID.randomUUID().toString() : m_oId;
        role[1] = m_jName.getText();
        return role;
    }
    

    public Component getComponent() {
        return this;
    }
    

    public void refresh() {
    }
    
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        m_jName = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();

        setLayout(null);

        m_jName.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        add(m_jName);
        m_jName.setBounds(90, 10, 260, 25);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("pos_messages"); // NOI18N
        jLabel1.setText(bundle.getString("label.name")); // NOI18N
        add(jLabel1);
        jLabel1.setBounds(10, 10, 70, 25);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("All Permissions");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Sales");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Refunds");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Products");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Reports");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("CSV Import");
        treeNode1.add(treeNode2);
        jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane1.setViewportView(jTree1);

        add(jScrollPane1);
        jScrollPane1.setBounds(10, 50, 410, 410);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTree jTree1;
    private javax.swing.JTextField m_jName;
    // End of variables declaration//GEN-END:variables
}
